package com.woniuxy.classteacher.mqsend;

import com.woniuxy.commons.entity.StudentInfo;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.UUID;

/**
 * @Auther: 牟强
 * @Date: 2020/7/18/018 14:31
 * @Description: 向邮件和手机短信队列发送消息
 */
@Component
public class EmailPhone {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void send(StudentInfo student) {
        //自定义消息的id
        CorrelationData correlationData = new CorrelationData();

        String id = UUID.randomUUID().toString();
        System.out.println("发送id " + id);
        correlationData.setId(id);
        //参数1：交换机的名字    参数2：路由   参数3：消息
        rabbitTemplate.convertAndSend("fanoutExchange", "", student, correlationData);
    }
}
